package engine.content;


import java.io.StringReader;
import java.util.Iterator;

import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedInput;


public class RSSContent implements IContent<String, SyndFeed> {

	String contentType,contentBase,contentStr;
	private SyndFeed content;

	@Override
	public SyndFeed getContent() {
		return content;
	}
	
	@Override
	public void setContent(String contentStr) throws FeedException {
		this.contentStr = contentStr;
		SyndFeedInput input = new SyndFeedInput();
		StringReader sr = new StringReader(this.contentStr);
		content = input.build(sr);
		
	}

	@Override
	public ContentTypes getType() {
		return ContentTypes.RSS;
	}
	
	
	@Override
	public String getContentType() {
		return contentType;
		
	}

	@Override
	public void setContentType(String contentTypeStr) {
		this.contentType = contentTypeStr;
	}
	
	
	@Override
	public String getContentBase() {
		return contentBase;
		
	}

	@Override
	public void setContentBase(String contentBaseStr) {
		this.contentBase = contentBaseStr;
	}
	
	@SuppressWarnings("unchecked")
	public Iterator<SyndEntry> getFeedIterator() {
		return content.getEntries().iterator();
	}
	
	@Override
	public String getContentAsString() {
		return contentStr;
	}
	
	@Override
	public String getFileSuffix() {
		return "xml";
	}
}
